<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
<!--                <div class="layui-input-inline">-->
<!--                    <input type="text" class="layui-input searchVal" placeholder="请输入搜索的内容" />-->
<!--                </div>-->
                <a class="layui-btn add_btn" data-type="reload">增加</a>
            </div>
            <!--            <div class="layui-inline">-->
            <!--                <a class="layui-btn layui-btn-normal addUsers_btn">添加用户</a>-->
            <!--            </div>-->
            <!--            <div class="layui-inline">-->
            <!--                <a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>-->
            <!--            </div>-->

        </form>
    </blockquote>
    <table id="productList" lay-filter="productListFilter"></table>

    <!--操作-->
    <script type="text/html" id="productListBar">
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="editType">更改</a>
    </script>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        //商品列表
        var tableIns = table.render({
            elem: '#productList',
            url : 'product/typeList',
            page : true,
            height : "full-125",
            limit : 20,
            limits : [10,15,20,25],
            id : "productListTable",
            cols : [[
                // {type: "checkbox", fixed:"left"},
                {field: 'id', title: '分类id',align:"center"},
                {field: 'type', title: '商品类型',align:"center"},
                {title: '操作', width:100, templet:'#productListBar',fixed:"right",align:"center"}
            ]]
        });

        //点击的操作
        table.on("tool(productListFilter)",function (obj) {
            console.log(obj)
            //获取当前行的数据
            var data=obj.data;
            switch (obj.event){
                case 'delType':
                    deleteType(data);
                    break;
                case 'editType':
                    editType(data);
                    break;

            }
        });
        //删除
        function deleteType(data){
            $.ajax({
                //url:"product/deleteProduct/"+data.productSn,
                type:"DELETE",
                success:function (res) {
                    if(res.code==200){
                        layer.msg(res.msg);
                        tableIns.reload();//重新刷新表格
                    }
                }
            });
        };
        //更改,弹出更改的一个框
        function editType(data) {
            var index=layui.layer.open({
                title:'更改商品分类',
                type:2,
                area:['200px','300px'],
                content:'toEditCategory.do',
                success:function (layero,index) {
                    var body = layui.layer.getChildFrame('body', index);//少了这个是不能从父页面向子页面传值的
                    body.contents().find(".beforeType").val(data.type);
                    body.contents().find(".typeCode").val(data.id);
                }
            });

        }




    })

</script>
</body>
</html>